import React, { Component } from 'react'
import { connect } from 'dva'
import MyNavBar from 'components/navbar';
import styles from './index.less'
import { MyIcon } from 'components/my-icon';
import { Button } from 'antd-mobile'
import router from 'umi/router';
import { ENTER_TYPE, PROCESS_STATUS, COUNT_DOWN } from 'utils/Enum'
import { getIsDingTalk, backToOut } from 'utils/utils';
import commonStyles from 'utils/common.less';
/**
 * @description 企业认证结果页面
 * @author 马羽
 * @date 2019-12-29
 * @class EnterpriseCertificationResult
 * @extends {Component}
 */

@connect(({ EnterpriseCertificationResultModel }) => ({ EnterpriseCertificationResultModel }))
class EnterpriseCertificationResult extends Component {

    /**
     * 传入状态status判断显示结果 210成功 211失败
     * msg 显示错误信息 默认未知错误
     * example /EnterpriseCertificationResult?status=211r&msg=企业已实名认证
     */
    link = 'http://signit-wesign.mikecrm.com/W5RKpG1'
    
    render() {
        let { status, msg } = this.props.EnterpriseCertificationResultModel
        let returnUrl = localStorage.getItem('returnUrl')
        let enterType = localStorage.getItem('enterType')
        let isExternal = enterType === ENTER_TYPE.EXTERNAL ? true : false  //判断是不是从外部进入
        let url = ''
        //如果是从外部进入就赋值外部地址，否则赋值返回首页
        url = isExternal ? returnUrl : `/Signature`
        const isDingTalk = getIsDingTalk()

        // const contentContainer=commonStyles.result+' '+commonStyles.headerTop
        const contentContainer = isDingTalk === 'true' ? commonStyles.result : commonStyles.result + ' ' + commonStyles.headerTop

        return (
            <div className={styles.baseLayout}>

                <MyNavBar title={"企业认证"} backUrl={url} isExternal={isExternal} gobackStatus={true} />

                <div className={contentContainer}>
                    <div className={commonStyles.IconImg}>
                        <MyIcon type={status == PROCESS_STATUS.EUSR_AUTHORIZING_SUCCESS ? 'iconchenggong' : 'iconClose'} className={status === 'success' ? styles.success : styles.error} />
                    </div>
                    <div className={commonStyles.titleSuccess}>
                        <span>
                            {
                                status == PROCESS_STATUS.EUSR_AUTHORIZING_SUCCESS ?
                                    '恭喜您，企业认证成功'
                                    :
                                    '企业认证失败'
                            }
                        </span>
                    </div>
                    {/* {
                        status == PROCESS_STATUS.EUSR_AUTHORIZING_SUCCESS ?
                            null
                            :
                            <div className={commonStyles.titleJump}>
                                <span>
                                    {msg}
                                </span>
                            </div>
                    } */}
                </div>
                {
                    status == PROCESS_STATUS.EUSR_AUTHORIZING_SUCCESS ?
                    null
                    :
                    <div className={styles.middle}>
                        <div>可能的原因</div>
                        <div>1、资料填写错误，请检查资料重新认证</div>
                        <div>2、政府、事业单位、民办非企业单位等其他组织可以<a className={styles.link} href={this.link}>申请人工审核</a></div>
                    </div>
                }
                <div className={styles.footer + ' ' + commonStyles.footerContainer}>
                    <Button
                        type="primary"
                        shape="round"
                        onClick={this.goNext.bind(this, url, isExternal)}
                    >
                        {
                            status == PROCESS_STATUS.EUSR_AUTHORIZING_SUCCESS ?
                            '返回'
                            :
                            '返回重试'
                        }
                    </Button>
                </div>
            </div>
        )
    }

    goNext = (url, isExternal) => {
        if (isExternal) {
            backToOut();
        } else {
            router.push(url)
        }
    }
}

export default EnterpriseCertificationResult
